﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Modules_Module_BBS_Content : System.Web.UI.UserControl
{
    protected int AddBBSRecord(string name, string title, string content, string parent)
    {
        string btime;
        btime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        string strSQL;
        strSQL = "INSERT INTO bbs(username,title,content,parent,time) VALUES (";
        strSQL += "'" + name + "'";
        strSQL += ",'" + title + "'";
        strSQL += ",'" + content + "'";
        strSQL += ",'" + parent + "'";
        strSQL += ",'" + btime + "')";
        MysqlHelp MHBBSNew = new MysqlHelp();
        int result = MHBBSNew.Runsql(strSQL);
        return result;
    }
    private string strID;
    protected void Page_Load(object sender, EventArgs e)
    {
        int bbsid = Convert.ToInt32(Request["BBSID"].ToString());
        string strSQL;
        strSQL = "SELECT * FROM bbs WHERE id='" + bbsid + "' OR parent='" + bbsid + "'ORDER BY time DESC";
        MysqlHelp BBSMH = new MysqlHelp();
        DataTable BBSTable = new DataTable();
        BBSTable = BBSMH.GetDatabysql(strSQL);
//         Counter.Text = BBSTable.Rows[0]["title"].ToString();
//         string IDTemp = BBSTable.Rows[0]["id"].ToString();
        ViewState["strID"] = bbsid;
        this.GridViewContent.DataSource = BBSTable;
        this.GridViewContent.DataBind();
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        string name, titile, content,parent;
        name = "lijiabin";
        titile = "回复";
        content = this.TextBox_content.Text.Trim();
        parent = ViewState["strID"].ToString();
        if (!string.IsNullOrEmpty(titile) && !string.IsNullOrEmpty(content))
        {
            AddBBSRecord(name, titile, content, parent);
            Response.Write("<script language=javascript>alert('感谢您的回复!');</script>");
        }
        this.TextBox_content.Text = string.Empty;
        Response.AddHeader("Refresh", "0");
    }
}
